package com.pps.sdk.tester;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class UINavigation extends LinearLayout{
	private TextView titleView;
	private Button backBtn;
	private Button doneBtn;

	@SuppressLint("NewApi")
	public UINavigation(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		initNavigation(context);
	}

	public UINavigation(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		initNavigation(context);
	}

	public UINavigation(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initNavigation(context);
	}

	private void initNavigation(Context context){
		LayoutInflater inflater = LayoutInflater.from(context);
		inflater.inflate(R.layout.top_navigation, this, true);
		backBtn = (Button) findViewById(R.id.back);
		titleView = (TextView) findViewById(R.id.title);
		doneBtn = (Button) findViewById(R.id.done);
	}
	
	public void setTitle(boolean isShow, String title){
		if(isShow){
			titleView.setVisibility(View.VISIBLE);
			if(!TextUtils.isEmpty(title)){
				titleView.setText(title);
			}
			
			return ;
		}
		
		titleView.setVisibility(View.GONE);
	}
	
	public void setLeftBtn(boolean isShow, String text, int background, OnClickListener listener){
		if(isShow){
			if(!TextUtils.isEmpty(text)){
				backBtn.setText(text);
			}
			
			if(background != 0){
				backBtn.setBackgroundResource(background);
			}
			
			if(listener != null){
				backBtn.setOnClickListener(listener);
			}
			
			backBtn.setVisibility(View.VISIBLE);
			return ;
		}
		
		backBtn.setVisibility(View.GONE);
	}
	
	public void setRightBtn(boolean isShow, String text, int background, OnClickListener listener){
		if(isShow){
			if(!TextUtils.isEmpty(text)){
				doneBtn.setText(text);
			}
			
			if(background != 0){
				doneBtn.setBackgroundResource(background);
			}
			
			if(listener != null){
				doneBtn.setOnClickListener(listener);
			}
			
			doneBtn.setVisibility(View.VISIBLE);
			return ;
		}
		
		doneBtn.setVisibility(View.GONE);
	}
	
}
